<?php
namespace Home\Controller;
use Think\Controller;
use Org\Util\Step;
use Think\page;
class ListController extends Controller {
	public function index(){
    	import("Org.Util.Step");
    	$btid = $_GET['btid'];//子分类的id    	
    	//分类列表    	
    	$all = M('step')->order('sort')->select();
    	$step = Step::showfenlei($all);    	
    	$this->assign('step',$step);
    	//主体博文
    	$boke = D('bokegl')->relation(true)->where(array('del' => 0))->select();
    	$this->assign('boke',$boke);    
    	//推荐博文
    	$recommend = D('bokegl')->relation(true)->where(array('del' =>0 , 'attr[id]' =>(array('IN',2))))->limit(10)->select();
    	$this->assign('recommend',$recommend);
    	//最新发布博文
    	$new = M('boke')->order('time desc')->where(array('del' => 0))->limit(8)->select();    	
    	$this->assign('new',$new);
    	//所选列表下的所有文章
    	$child = Step::getchild($all, $btid);  //取得顶级分类下的所有子分类id
    	array_unshift($child,$btid);    	   //把顶级分类放入数组
    	import('Think.Page');
    	$count = D('bokegl')->relation(true)->where(array('cid' => array('IN',$child),'del' =>0))->count();
    	$page  = new page($count,5);
    	$show = $page->show(); // 分页显示输出
    	$this->assign('page',$show);// 赋值分页输出
    	$list = D('bokegl')->relation(true)->where(array('cid' => array('IN',$child),'del' =>0))->limit($page->firstRow.','.$page->listRows)->select();
    	$this->assign('list',$list); 
    	$this->display();
    }    
    public function serach(){
    	$name = $_POST['name'];
    	$where = (
    			array('name'=>$name)
    			);
    	$count = M('step')->where($where)->count();
    	if(!$count)
    	{$this->error("没有该列表！");}
    	else{
    		$arr = M('step')->where($where)->find();
    		$id = $arr['id'];
    		$this->redirect('Home/List/index/btid/'.$id);
    	}
    }
    public function jump(){
    	$jumpid = $_GET['jumpid']; //show位置超链接的id
    	import("Org.Util.Step");
    	//分类列表
    	$m = M('step');
    	$all = $m->order('sort')->select();
    	$step = Step::showfenlei($all);
    	$this->assign('step',$step);
    	//主体博文
    	$boke = D('bokegl')->relation(true)->where(array('del' => 0))->select();
    	$this->assign('boke',$boke);    
    	//推荐博文
    	$recommend = D('bokegl')->relation(true)->where(array('del' =>0 , 'attr[id]' =>(array('IN',2))))->limit(8)->select();
    	$this->assign('recommend',$recommend);
    	//最新发布博文
    	$new = M('boke')->order('time')->where(array('del' =>0))->limit(8)->select();
    	$this->assign('new',$new);
    	//所选列表下的所有文章
    	$child = Step::getchild($all, $jumpid);
    	array_unshift($child,$jumpid);
    	$list = D('bokegl')->relation(true)->where(array('cid' => array('IN',$child),'del' =>0))->select();
    	$this->assign('list',$list);
    	$this->display('List/index');
    }
}